// pages/confirm-pay/confirm-pay.js
var app = getApp();
var getMyAssetUrl = "AssetsApi/getMyAssetsV2";
var selectPayResultUrl = "userOrderApi/selectPayResult";


 var payType;
var totalMoney;
var batchNo;
Page({
  data: {
    totalMoney:0,
  },

  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function (options) {
    console.log(options)
    var that = this; 
    var money = options.money;
    totalMoney = parseFloat(money).toFixed(2);
    batchNo = options.batchNo

    that.setData({
     totalMoney: totalMoney
    })

    wx.request({

      url: app.globalData.requestUrl + getMyAssetUrl,
      header: {
        'content-type': 'application/json'
      },
      method: 'POST',
      data: {//这里写你要请求的参数
        userId: app.globalData.userId,
        deviceType: 'C142001',
      },

      success: (res) => {
         console.log(res)
         var balance = res.data.data.kyye;
         var ableBalance = parseFloat(balance).toFixed(2);
        that.setData({
          ableBalance: ableBalance
        });
       
      }

    })


    
  },

  radioChange:function(e){
    console.log(e)
    if (e.detail.value == "balance"){
        payType = "C163004";
    } else{
        payType = "C163002";
      }
  },

  confirmPay:function(e){

        var that = this;
       console.log(e)
       if (payType == "C163004"){//余额支付

         wx.request({

           url: app.globalData.requestUrl + selectPayResultUrl,
           header: {
             'content-type': 'application/json'
           },
           method: 'POST',
           data: {//这里写你要请求的参数
             userId: app.globalData.userId,
             deviceType: 'C142001',
             orderNo: batchNo,
             orderNoType:2,
             amount: totalMoney,
             payType: payType,
             'from': "C191001",
             signType: 'MD5',
           },

           success: (res) => {
             console.log(res)

            //  that.setData({

            //  });
            var list = res.data.data;
            for(var i=0;i<list.length;i++){
              var id =list[i].id;
            }
            console.log(id)
             wx.navigateTo({ 
               url: "/pages/order-result/order-result?id=" + id + "&batchNo=" + batchNo + "&totalMoney=" + totalMoney + "&payType=" + payType
             });

           }

         })
       }else{

       }

  },

  /**
   * 生命周期函数--监听页面显示
   */
  onShow: function () {
  
  },


})